package com.liuqing.www.加密算法.tx加密算法;

/*     */ 
/*     */ public class Base64NoBr
/*     */ {
/*   9 */   private static final byte[] DECODE_TABLE = { 
/*  11 */     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 
/*  12 */     53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 
/*  13 */     3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
/*  14 */     21, 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26, 27, 28, 29, 30, 31, 32, 
/*  15 */     33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 
/*  16 */     50, 51 };
/*     */ 
/*  19 */   private static final byte[] ENCODE_TABLE = { 65, 66, 67, 68, 69, 
/*  20 */     70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 
/*  21 */     87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 
/*  22 */     108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 
/*  23 */     121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 45, 47 };
/*     */ 
/*     */   static
/*     */   {
/*  29 */     int index = 0;
/*  30 */     for (char c = 'A'; c <= 'Z'; c = (char)(c + '\001'))
/*  31 */       ENCODE_TABLE[(index++)] = (byte)c;
/*  32 */     for (char c = 'a'; c <= 'z'; c = (char)(c + '\001'))
/*  33 */       ENCODE_TABLE[(index++)] = (byte)c;
/*  34 */     for (char c = '0'; c <= '9'; c = (char)(c + '\001'))
/*  35 */       ENCODE_TABLE[(index++)] = (byte)c;
/*  36 */     ENCODE_TABLE[(index++)] = 45;
/*  37 */     ENCODE_TABLE[(index++)] = 47;
/*     */ 
/*  40 */     for (int i = 0; i < 64; ++i)
/*  41 */       DECODE_TABLE[ENCODE_TABLE[i]] = (byte)i;
/*     */   }
/*     */ 
/*     */   public static byte[] encode(byte[] data)
/*     */   {
/*  46 */     if (data == null) {
/*  47 */       return null;
/*     */     }
/*  49 */     int fullGroups = data.length / 3;
/*  50 */     int resultBytes = fullGroups * 4;
/*  51 */     if (data.length % 3 != 0) {
/*  52 */       resultBytes += 4;
/*     */     }
/*  54 */     byte[] result = new byte[resultBytes];
/*  55 */     int resultIndex = 0;
/*  56 */     int dataIndex = 0;
/*  57 */     int temp = 0;
/*  58 */     for (int i = 0; i < fullGroups; ++i)
/*     */     {
/*  60 */       temp = (data[(dataIndex++)] & 0xFF) << 16 | 
/*  61 */         (data[(dataIndex++)] & 0xFF) << 8 | data[(dataIndex++)] & 
/*  62 */         0xFF;
/*     */ 
/*  64 */       result[(resultIndex++)] = ENCODE_TABLE[(temp >> 18 & 0x3F)];
/*  65 */       result[(resultIndex++)] = ENCODE_TABLE[(temp >> 12 & 0x3F)];
/*  66 */       result[(resultIndex++)] = ENCODE_TABLE[(temp >> 6 & 0x3F)];
/*  67 */       result[(resultIndex++)] = ENCODE_TABLE[(temp & 0x3F)];
/*     */     }
/*  69 */     temp = 0;
/*  70 */     while (dataIndex < data.length)
/*     */     {
/*  72 */       temp <<= 8;
/*  73 */       temp |= data[(dataIndex++)] & 0xFF;
/*     */     }
/*  75 */     switch (data.length % 3)
/*     */     {
/*     */     case 1:
/*  78 */       temp <<= 8;
/*  79 */       temp <<= 8;
/*  80 */       result[(resultIndex++)] = ENCODE_TABLE[(temp >> 18 & 0x3F)];
/*  81 */       result[(resultIndex++)] = ENCODE_TABLE[(temp >> 12 & 0x3F)];
/*  82 */       result[(resultIndex++)] = 61;
/*  83 */       result[(resultIndex++)] = 61;
/*  84 */       break;
/*     */     case 2:
/*  86 */       temp <<= 8;
/*  87 */       result[(resultIndex++)] = ENCODE_TABLE[(temp >> 18 & 0x3F)];
/*  88 */       result[(resultIndex++)] = ENCODE_TABLE[(temp >> 12 & 0x3F)];
/*  89 */       result[(resultIndex++)] = ENCODE_TABLE[(temp >> 6 & 0x3F)];
/*  90 */       result[(resultIndex++)] = 61;
/*     */     }
/*     */ 
/*  96 */     return result;
/*     */   }
/*     */ 
/*     */   public static byte[] decode(byte[] base64Data)
/*     */   {
/* 101 */     if (base64Data == null)
/* 102 */       return null;
/* 103 */     if (base64Data.length == 0)
/* 104 */       return new byte[0];
/* 105 */     if (base64Data.length % 4 != 0) {
/* 106 */       throw new IllegalArgumentException("数据不完整，长度为：" + base64Data.length);
/*     */     }
/* 108 */     byte[] result = (byte[])null;
/* 109 */     int groupCount = base64Data.length / 4;
/*     */ 
/* 111 */     int lastData = base64Data.length;
/* 112 */     while (base64Data[(lastData - 1)] == 61)
/*     */     {
/* 114 */       if (--lastData == 0)
/* 115 */         return new byte[0];
/*     */     }
/* 117 */     result = new byte[lastData - groupCount];
/*     */ 
/* 119 */     int temp = 0;
/* 120 */     int resultIndex = 0;
/* 121 */     int dataIndex = 0;
/* 122 */     while (dataIndex + 4 < base64Data.length)
/*     */     {
/* 124 */       temp = DECODE_TABLE[base64Data[(dataIndex++)]];
/* 125 */       temp = (temp << 6) + DECODE_TABLE[base64Data[(dataIndex++)]];
/* 126 */       temp = (temp << 6) + DECODE_TABLE[base64Data[(dataIndex++)]];
/* 127 */       temp = (temp << 6) + DECODE_TABLE[base64Data[(dataIndex++)]];
/*     */ 
/* 129 */       result[(resultIndex++)] = (byte)(temp >> 16 & 0xFF);
/* 130 */       result[(resultIndex++)] = (byte)(temp >> 8 & 0xFF);
/* 131 */       result[(resultIndex++)] = (byte)(temp & 0xFF);
/*     */     }
/*     */ 
/* 134 */     temp = 0;
/* 135 */     int j = 0;
/* 136 */     for (; dataIndex < base64Data.length; ++j) {
/* 137 */       temp = (temp << 6) + DECODE_TABLE[base64Data[dataIndex]];
/*     */ 
/* 136 */       ++dataIndex;
/*     */     }
/* 138 */     for (; j < 4; ++j) {
/* 139 */       temp <<= 6;
/*     */     }
/* 141 */     result[(resultIndex++)] = (byte)(temp >> 16 & 0xFF);
/* 142 */     if (base64Data[(dataIndex - 2)] != 61)
/* 143 */       result[(resultIndex++)] = (byte)(temp >> 8 & 0xFF);
/* 144 */     if (base64Data[(dataIndex - 1)] != 61) {
/* 145 */       result[(resultIndex++)] = (byte)(temp & 0xFF);
/*     */     }
/* 147 */     return result;
/*     */   }
/*     */ }

/* Location:           C:\Documents and Settings\韩世超\桌面\NetGameApp_chuhan.jar
 * Qualified Name:     com.tencent.wapgame.netgame.util.Base64NoBr
 * JD-Core Version:    0.5.4
 */